package com.itnoob.config;

import com.itnoob.log.Logger;
import com.itnoob.log.impl.ConsoleLoggerImpl;
import com.itnoob.log.impl.DatabaseLoggerImpl;
import com.itnoob.log.impl.FileLoggerImpl;
import com.itnoob.logger.AbstractLogger;
import com.itnoob.logger.impl.FormattedoggerImpl;
import com.itnoob.logger.impl.SimpleLoggerImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhoujun
 * @date 2025/3/20 22:41
 */
@Configuration
public class LoggerConfig {

    @Value("${logging.type}")
    private String type;

    @Value("${logging.file-name:defaultLog.txt}")
    private String fileName;


    @Value("${logging.format}")
    private boolean format;



    @Bean
    public Logger  logger(){
        switch (type){
            case "console":
                return new ConsoleLoggerImpl();
            case "file":
                return new FileLoggerImpl(fileName);
            case "database":
                return new DatabaseLoggerImpl(); //数据库就不实现了
            default:
                throw new IllegalArgumentException("Invalid loggint type:" + type);
        }
    }

    @Bean
    public AbstractLogger abstractLogger(Logger logger){
        if (format){
            return new FormattedoggerImpl(logger);
        }else{
            return new SimpleLoggerImpl(logger);
        }


    }

}
